Attribute VB_Name = "input"
Option Explicit

Public controller1 As Long 'SMS Controller 1.
Public controller2 As Long 'SMS Controller 2.
Public ggcontroller As Long 'GG Controller.

Public RFU1 As Boolean 'rapid fire c1b1
Public RFU2 As Boolean 'rapid fire c1b2
Public RFU1Bool As Boolean 'rapid fire c1b1 toggler
Public RFU2Bool As Boolean 'rapid fire c1b2 toggler
Public RFU12 As Boolean 'control 2 start
Public RFU22 As Boolean
Public RFU1Bool2 As Boolean
Public RFU2Bool2 As Boolean 'control 2 end

Public Input1_Up As Integer
Public Input1_Down As Integer
Public Input1_Left As Integer
Public Input1_Right As Integer
Public Input1_1 As Integer
Public Input1_2 As Integer
Public Input1_GGStart As Integer
Public Input1_Pause As Integer
Public Input1_UseGamepad As Boolean
Public Input1_WhichGamepad As Long

Public Input2_Up As Integer
Public Input2_Down As Integer
Public Input2_Left As Integer
Public Input2_Right As Integer
Public Input2_1 As Integer
Public Input2_2 As Integer
Public Input2_UseGamepad As Boolean
Public Input2_WhichGamepad As Long

Public Joy1_1 As Long
Public Joy1_2 As Long
Public Joy1_GGStart As Long
Public Joy1_Pause As Long
Public Joy2_1 As Long
Public Joy2_2 As Long

Public Const JOY_BUTTON1 As Long = &H1
Public Const JOY_BUTTON2 As Long = &H2
Public Const JOY_BUTTON3 As Long = &H4
Public Const JOY_BUTTON4 As Long = &H8
Public Const JOY_BUTTON5 As Long = &H10
Public Const JOY_BUTTON6 As Long = &H20
Public Const JOY_BUTTON7 As Long = &H40
Public Const JOY_BUTTON8 As Long = &H80
Public Const JOY_BUTTON9 As Long = &H100
Public Const JOY_BUTTON10 As Long = &H200
Public Const JOY_BUTTON11 As Long = &H400
Public Const JOY_BUTTON12 As Long = &H800

Public Const JOYERR_NOERROR = 0
Public Const JOYERR_BASE As Long = 160
Public Const JOYERR_UNPLUGGED As Long = (JOYERR_BASE + 7)

Public Const JOYSTICK1 As Long = &H0
Public Const JOYSTICK2 As Long = &H1

Public Const MAXPNAMELEN = 32
Public Const MMSYSERR_BASE As Long = 0
Public Const MMSYSERR_INVALPARAM As Long = (MMSYSERR_BASE + 11)
Public Const MMSYSERR_NODRIVER As Long = (MMSYSERR_BASE + 6)

Public Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As Long, lpCaps As JOYCAPS, ByVal uSize As Long) As Long
Public Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JoyInfo) As Long

Public Type JOYCAPS
  wMid As Integer
  wPid As Integer
  szPname As String * MAXPNAMELEN
  wXmin As Long
  wXmax As Long
  wYmin As Long
  wYmax As Long
  wZmin As Long
  wZmax As Long
  wNumButtons As Long
  wPeriodMin As Long
  wPeriodMax As Long
End Type

Public Type JoyInfo
  wXpos As Long
  wYpos As Long
  wZpos As Long
  wButtons As Long
End Type
Public Sub JoystickInput()

  Dim JoyInformation As JoyInfo

  If Input1_UseGamepad = False And Input2_UseGamepad = False Then
    Exit Sub
  End If

  If Input1_UseGamepad = True Then
    If joyGetPos(Input1_WhichGamepad, JoyInformation) = JOYERR_NOERROR Then
      If JoyInformation.wXpos < 16000 Then Call frmSMS.picScreen_KeyDown(Input1_Left, False) Else Call frmSMS.picScreen_KeyUp(Input1_Left, False)
      If JoyInformation.wXpos > 48000 Then Call frmSMS.picScreen_KeyDown(Input1_Right, False) Else Call frmSMS.picScreen_KeyUp(Input1_Right, False)
      If JoyInformation.wYpos < 16000 Then Call frmSMS.picScreen_KeyDown(Input1_Up, False) Else Call frmSMS.picScreen_KeyUp(Input1_Up, False)
      If JoyInformation.wYpos > 48000 Then Call frmSMS.picScreen_KeyDown(Input1_Down, False) Else Call frmSMS.picScreen_KeyUp(Input1_Down, False)
      If (JoyInformation.wButtons And Joy1_1) Then Call frmSMS.picScreen_KeyDown(Input1_1, False) Else Call frmSMS.picScreen_KeyUp(Input1_1, False)
      If (JoyInformation.wButtons And Joy1_2) Then Call frmSMS.picScreen_KeyDown(Input1_2, False) Else Call frmSMS.picScreen_KeyUp(Input1_2, False)
      If (JoyInformation.wButtons And Joy1_GGStart) Then Call frmSMS.picScreen_KeyDown(Input1_GGStart, False) Else Call frmSMS.picScreen_KeyUp(Input1_GGStart, False)
      If (JoyInformation.wButtons And Joy1_Pause) Then Call frmSMS.picScreen_KeyDown(Input1_Pause, False) Else Call frmSMS.picScreen_KeyUp(Input1_Pause, False)
    Else
      GoTo 1
    End If
  Else
    GoTo 1
  End If

1:

  If Input2_UseGamepad = True Then
    If joyGetPos(Input1_WhichGamepad, JoyInformation) = JOYERR_NOERROR Then
      If JoyInformation.wXpos < 16000 Then Call frmSMS.picScreen_KeyDown(Input2_Left, False) Else Call frmSMS.picScreen_KeyUp(Input2_Left, False)
      If JoyInformation.wXpos > 48000 Then Call frmSMS.picScreen_KeyDown(Input2_Right, False) Else Call frmSMS.picScreen_KeyUp(Input2_Right, False)
      If JoyInformation.wYpos < 16000 Then Call frmSMS.picScreen_KeyDown(Input2_Up, False) Else Call frmSMS.picScreen_KeyUp(Input2_Up, False)
      If JoyInformation.wYpos > 48000 Then Call frmSMS.picScreen_KeyDown(Input2_Down, False) Else Call frmSMS.picScreen_KeyUp(Input2_Down, False)
      If (JoyInformation.wButtons And Joy2_1) Then Call frmSMS.picScreen_KeyDown(Input2_1, False) Else Call frmSMS.picScreen_KeyUp(Input2_1, False)
      If (JoyInformation.wButtons And Joy2_2) Then Call frmSMS.picScreen_KeyDown(Input2_2, False) Else Call frmSMS.picScreen_KeyUp(Input2_2, False)
    End If
  End If

End Sub

